/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GeraSenha.java
 *
 * Created on 01/12/2011, 16:00:39
 */
package senhatelefonia;

/**
 *
 * @author HYPERAPOIO_06
 */
public class GeraSenha extends javax.swing.JFrame {

    /**
     * Creates new form GeraSenha
     */
    public GeraSenha() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtEmpresa = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        txtEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEmpresaActionPerformed(evt);
            }
        });

        jButton1.setText("Gerar!");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(112, 112, 112)
                        .addComponent(txtEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(164, 164, 164)
                        .addComponent(jButton1)))
                .addContainerGap(126, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(txtEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEmpresaActionPerformed
    }//GEN-LAST:event_txtEmpresaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //nome da empresa
        String empresa = txtEmpresa.getText();
        //conta caracteres
        String num_caracteres = String.format("%02x", empresa.length());

        //pega o segundo caracter mais o proximo

        char letra2 = proximaLetra(1,empresa);
        
        //pega o ultimo caracter
        char letraUlt = proximaLetra(empresa.length(), empresa);
        //conta as vogais e consoantes
        /////----
        String nvogais = numVogais(empresa);
        String nconsoantes = numConsoantes(empresa);
        /////-----
        System.out.print(num_caracteres);
        System.out.print(letra2);
        System.out.print(letraUlt);
        System.out.print(nvogais);
        System.out.print(nconsoantes + "\n");

    }//GEN-LAST:event_jButton1ActionPerformed

    private String numVogais(String empresa) {
        char[] vogais = {'a', 'e', 'i', 'o', 'u'};
        int nvogais = 1, ie, iv;

        for (iv = 0; iv < vogais.length; iv++) {
            for (ie = 0; ie < empresa.length(); ie++) {
                if (empresa.charAt(ie) == vogais[iv]) {
                    nvogais++;
                }
            }
        }
        return String.format("%02x", nvogais);
    }

    private String numConsoantes(String empresa) {
        char[] consoantes = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'};
        int nconsoantes = 1, ie, iv;

        for (iv = 0; iv < consoantes.length; iv++) {
            for (ie = 0; ie < empresa.length(); ie++) {
                if (empresa.charAt(ie) == consoantes[iv]) {
                    nconsoantes++;
                }
            }
        }
        return String.format("%02x", nconsoantes);
    }
    
    private char proximaLetra(int posicao, String palavra){
        
        char letra2 = palavra.charAt(posicao);
        
        if (letra2 == 'l') {
            letra2 = 'k';
        } else if (letra2=='x') {
            letra2 = 'a';
        } else {
            letra2 = (char) ((int) (letra2) + 1);
        }
        return(letra2);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GeraSenha().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JTextField txtEmpresa;
    // End of variables declaration//GEN-END:variables
}
